﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using yiCommerce.Core;
using yiCommerce.Models.Statuses;
using yiCommerce.Service.FriendShips;
using yiCommerce.Service.Statuses;

namespace yiCommerce.Controllers
{
    public class StatusesController : Controller
    {


        private IStatusService _statusService;
        private IWorkContext _workContext;

        private IFriendShipService _friendShipService;

        private int pageSize = 5;

        public StatusesController(IStatusService statusService, IWorkContext workContext, IFriendShipService friendShipService)
        {
            _statusService = statusService;
            _workContext = workContext;
            _friendShipService = friendShipService;
        }

        public ActionResult Status(int statusId)
        {
            var status = _statusService.GetStatusById(statusId);
            var statusModel = Mapper.StatusMapper.ToStatusModel(status);
            ViewBag.Model = statusModel;
            return View();
        }
        public ActionResult Show(int customerId, int? pageIndex)
        {
            var isOwner = customerId == _workContext.CurrentCustomer.Id;

            var statuses = isOwner ? _statusService.HomeTimeLine(customerId, pageIndex.HasValue ? pageIndex.Value : 0, pageSize) : _statusService.UserTimeLine(customerId, pageIndex.HasValue ? pageIndex.Value : 0, pageSize);
            var model = new StatusListModel()
                {
                    IsFriend =  _friendShipService.IsFriend(_workContext.CurrentCustomer.Id, customerId),
                    IsOwner = isOwner,
                    CustomerId = customerId,
                    StatusList = Mapper.StatusMapper.PrepareStatusListItemModel(statuses)
                };
            ViewBag.Model = model;
            return View();
        }

        public ActionResult UserTimeLines(IList<int> customerIds)
        {
            return View();
        }


        //public ActionResult List()
        //{
        //    var statuses = _statusService.HomeTimeLine(_workContext.CurrentCustomer.Id);
        //    var model = new StatusListModel()
        //        {
        //            StatusList = yiCommerce.Mapper.StatusMapper.PrepareStatusListItemModel(statuses)
        //        };
        //    ViewBag.Model = model;
        //    return View();
        //}


    }
}
